@extends('app')

@section('content')
    <div class="layui-card" style="height:100vh;">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    @component('form.form',['id'=>'form'])
                        @include('form.input',[
                               'label' => '角色名称',
                               'name'  => 'name',
                               'class' => 'layui-col-md12',
                               'val'   => $model->name??''
                           ])

                        @include('form.textarea',[
                               'label' => '描述',
                               'name'  => 'description',
                               'class' => 'layui-col-md12',
                               'val'   => $model->description??''
                           ])

{{--                        <div class="layui-form-item">--}}
{{--                            <label class="layui-form-label"><span style="color:red">*</span>权限分配</label>--}}
{{--                            <div class="layui-input-block" style="border: 1px solid #e6e6e6;max-height: 300px;overflow:auto">--}}
{{--                                @foreach($nav as $item)--}}
{{--                                <div class="layui-unselect layui-form-checkbox layui-form-checked"><span>{{ $item['name'] }}</span>--}}
{{--                                    --}}{{--<i class="layui-icon layui-icon-ok"></i>--}}
{{--                                </div>--}}
{{--                                    @forelse($item['child'] as $child)--}}
{{--                                        <br>--}}
{{--                                        <input type="checkbox" name="role_nav_id[]" @if(isset($model->access) && in_array($child['id'],json_decode($model->access,true))) checked @endif title="{{ $child['name'] }}" value="{{ $child['id'] }}" lay-skin="">--}}
{{--                                        @forelse($child['child'] as $childer)--}}
{{--                                            <input type="checkbox" name="role_nav_id[]" @if(isset($model->access) && in_array($childer['id'],json_decode($model->access,true))) checked @endif title="{{ $childer['name'] }}" value="{{ $childer['id'] }}" lay-skin="primary" >--}}
{{--                                            @empty--}}
{{--                                        @endforelse--}}
{{--                                    @empty--}}

{{--                                    @endforelse--}}
{{--                                    <br>--}}
{{--                                @endforeach--}}
{{--                            </div>--}}
{{--                        </div>--}}

                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:red">*</span>权限分配</label>
                            <div class="layui-input-block" style="border: 1px solid #e6e6e6;max-height: 300px;overflow:auto">
                                <div class="layui-input" style="background: #FBFBFB;border: 0;border-bottom: 1px solid #e6e6e6;line-height: 36px">
{{--                                    <button class="layui-btn layui-btn-sm toggle" id="LAY-auth-tree-toggle" type="button">展开全部</button>--}}
{{--                                    <button class="layui-btn layui-btn-sm toggle" type="button">隐藏全部</button>--}}

                                    <button type="button" class="layui-btn layui-btn-sm" onclick="showAll('#LAY-auth-tree-index')">全部展开</button>
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="closeAll('#LAY-auth-tree-index')">全部隐藏</button>
                                </div>
                                <div id="LAY-auth-tree-index" style="padding: 0 10px"></div>
                            </div>
                        </div>
{{--                        <div class="layui-form-item">--}}
{{--                            <label class="layui-form-label">选择权限</label>--}}
{{--                            <div class="layui-input-block">--}}
{{--                                <--}}
{{--                            </div>--}}
{{--                        </div>--}}



                        @include('form.submit',['label'=>'立即提交','form'=>'form'])
                    @endcomponent
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
<script>
    layui.config({
        base: '/asset/' //静态资源所在路径
        ,version:true
    }).extend({
        index: 'lib/index', //主入口模块
        authtree:'lib/extend/authtree'
    }).use(['jquery', 'authtree', 'form', 'layer'], function(){
        var $ = layui.jquery;
        var authtree = layui.authtree;
        var form = layui.form;
        var layer = layui.layer;
        // 一般来说，权限数据是异步传递过来的


        var trees = '{!! json_encode($nav) !!}';
        authtree.render('#LAY-auth-tree-index', JSON.parse(trees), {
            inputname: 'role_nav_id[]',
            layfilter: 'lay-check-auth',
            nameKey:'name',
            valueKey:'id',
            childKey:'child',
            openall:true,
            themePath:'/asset/lib/extend/tree_themes/',
            theme: 'template',
            autowidth: true,
        });

        $('.toggle').on("click",function () {
            authtree.toggleAll('#LAY-auth-tree-index');
        })
    });

    function showAll(dst){
        layui.use(['jquery', 'layer', 'authtree'], function(){
            var layer = layui.layer;
            var authtree = layui.authtree;

            authtree.showAll(dst);
        });
    }
    // 闅愯棌鍏ㄩ儴
    function closeAll(dst){
        layui.use(['jquery', 'layer', 'authtree'], function(){
            var layer = layui.layer;
            var authtree = layui.authtree;

            authtree.closeAll(dst);
        });
    }


</script>
@endsection